package com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.impl;

import com.cicc.beergamevirtualsimulationsystem.common.webSocket.config.WebSocketMessageSender;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.JsonMessageHandler;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.Impl.CancelSelectRoleJsonWebSocketMessage;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.Impl.CurrentDataJsonWebSocketMessage;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.Impl.SomeoneChoosesRoleJsonWebSocketMessage;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.WebSocketMessageTypeEnum;
import com.cicc.beergamevirtualsimulationsystem.entity.RoomInfoManager;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.Collections;
import java.util.List;

@Component
public class CancelSelectRoleJsonMessageHandler implements JsonMessageHandler<CancelSelectRoleJsonWebSocketMessage> {
    @Override
    public void handle(WebSocketSession session, CancelSelectRoleJsonWebSocketMessage message) {
        String roomId = session.getAttributes().get("roomId").toString();
        String userId = session.getAttributes().get("userId").toString();
        RoomInfoManager.cancelRole(roomId,userId);
        WebSocketMessageSender.send(session,new CancelSelectRoleJsonWebSocketMessage("取消角色成功"));
//        String roomInfo = RoomInfoManager.getRoomInfo(roomId.toString(),userId);
        WebSocketMessageSender.sendMessageToRoom((String) roomId,new SomeoneChoosesRoleJsonWebSocketMessage());


    }

    @Override
    public String type() {
        return WebSocketMessageTypeEnum.PLAYER_CANCEL_SELECT_ROLE.getValue();
    }

    @Override
    public Class<CancelSelectRoleJsonWebSocketMessage> getMessageClass() {
        return CancelSelectRoleJsonWebSocketMessage.class;
    }
}
